package com.huika.dealontop.utils;

/**
 * Author: Victor Wu <br/>
 * Email: victor-wu*foxmail.com <br/>
 * Time: 2016/1/19 10:28 <br/>
 * Description: 无限倒计时工具
 */
public class HKCountDownTask implements Runnable {

    private long delay = 2000;  //default delay is 2000 MS

    private Runnable mRun;

    public HKCountDownTask(Runnable runnable){
        this.mRun = runnable;
    }

    public void start() {
        stop();
        // 执行延时操作
        UIUtils.postDelayed(this, delay);
    }

    public void stop() {
        UIUtils.removeCallbacks(this);
    }

    @Override
    public void run() {
        if(this.mRun != null){
            this.mRun.run();
        }
        UIUtils.postDelayed(this, delay);
    }

    public void setDelay(long delay) {
        this.delay = delay;
    }

}
